package com.liuxinlong.modules.patent.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.request.QueryBaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.PatentTrends;
import com.liuxinlong.modules.patent.controller.request.QueryPatentTrendsReq;
import com.liuxinlong.modules.patent.controller.request.UpdatePatentTrendsReq;
import com.liuxinlong.modules.patent.service.PatentTrendsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 专利动态控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023-09-15
 */
@RestController
@RequestMapping("/patent-trends")
public class PatentTrendsController {

    @Autowired
    private PatentTrendsService patentTrendsService;

    /**
     * 分页查询专利动态信息列表
     *
     * @param req 请求信息
     * @return 专利动态信息
     */
    @PostMapping("page")
    public BaseResp pagePatentTrendsInfo(@RequestBody QueryPatentTrendsReq req) {
        Map<String, Object> queryParam = new HashMap<>();
        queryParam.put("trendsMonth",req.getTrendsMonth());
        queryParam.put("productClass",req.getProductClass());
        queryParam.put("recommend",req.getRecommend());
        queryParam.put("startNum", req.getStartNum());
        queryParam.put("pageSize", req.getPageSize());
        Map<String, Object> dataMap = patentTrendsService.queryPatentTrendsInfo(queryParam);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("查询专利动态信息成功");
        resp.setDataMap(dataMap);
        return resp;
    }

    /**
     * 新增专利动态信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("add")
    @LogAnnotation(value = "新增专利动态", business = LogBusinessConstants.PATENT_TRENDS, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addPatentTrends(@RequestBody UpdatePatentTrendsReq req) {
        PatentTrends patentTrends = new PatentTrends();
        patentTrends.setTrendsMonth(req.getTrendsMonth());
        patentTrends.setProductClass(req.getProductClass());
        patentTrends.setTrendsPicture(req.getTrendsPicture());
        patentTrends.setTrendsAttach(req.getTrendsAttach());
        patentTrends.setRemark(req.getRemark());
        patentTrendsService.addPatentTrends(patentTrends);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增专利动态信息成功");
        return resp;

    }

    /**
     * 修改专利信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("update")
    @LogAnnotation(value = "修改专利动态", business = LogBusinessConstants.PATENT_TRENDS, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updatePatentTrends(@RequestBody UpdatePatentTrendsReq req) {
        PatentTrends patentTrends = new PatentTrends();
        patentTrends.setId(req.getId());
        patentTrends.setTrendsMonth(req.getTrendsMonth());
        patentTrends.setProductClass(req.getProductClass());
        patentTrends.setTrendsPicture(req.getTrendsPicture());
        patentTrends.setTrendsAttach(req.getTrendsAttach());
        patentTrends.setRemark(req.getRemark());
        patentTrendsService.updatePatentTrends(patentTrends);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改专利动态信息成功");
        return resp;
    }

    /**
     * 删除专利信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("delete")
    @LogAnnotation(value = "删除专利动态", business = LogBusinessConstants.PATENT_TRENDS, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deletePatentTrends(@RequestBody BaseDeleteReq req) {
        patentTrendsService.deletePatentTrends(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除专利动态信息成功");
        return resp;
    }

    /**
     * 导出专利动态信息
     *
     * @param response response
     * @return 导出数据
     */
    @PostMapping("export")
    @LogAnnotation(value = "导出专利动态信息", business = LogBusinessConstants.PATENT_TRENDS, operateType = LogOperateConstants.OPERATE_EXPORT)
    public void exportPatentTrends(@RequestBody QueryBaseReq req, HttpServletResponse response) {
        patentTrendsService.exportPatentTrends(req.getId(), response);
    }

    /**
     * 修改专利精选状态
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("recommend-update")
    @LogAnnotation(value = "修改专利精选状态", business = LogBusinessConstants.PATENT_TRENDS, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateRecommendStatus(@RequestBody QueryBaseReq req) {
        patentTrendsService.updateRecommendStatus(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改专利精选状态成功");
        return resp;
    }

}
